
function formatRepo (repo) {
	  if (repo.loading) return repo.text;
	    var markup =repo.title;
	    return markup;
  }

  function formatRepoSelection (repo) {
	  return repo.name || repo.text;
  }
function createContentSelect2(selectId){
	var select=$("#"+selectId).select2({
		allowClear: true,
		language: "zh-CN",
	    ajax: {
	      url: "cms/content/query.htm",
	      dataType: 'json',
	      delay: 250,
	      data: function (params) {
	    	  params["page"]=1;
	        return {
	          limit:100,
	          title: params.term, // search term
	          offset: params.page
	        };
	      },
	      processResults: function (data, params) {
	        // parse the results into the format expected by Select2
	        // since we are using custom formatting functions we do not need to
	        // alter the remote JSON data, except to indicate that infinite
	        // scrolling can be used
	        params.page = params.page || 1;
	        
	        var l=data.rows.length;
             for(var i=0;i<l;i++){
            	 data.rows[i].id=data.rows[i].id;
               	 data.rows[i]["text"]=data.rows[i].title;
             }
	         return {
	          results: data.rows,
	          pagination: {
	            more: (params.page * 30) < data.totalCount
	          }
	        };
	      },
	      cache: true
	    },
	    escapeMarkup: function (markup) { return markup; },
	    minimumInputLength: 1,
	    templateResult: formatRepo,
	    templateSelection: formatRepoSelection
	  });
	$(".select2-container--default").css({"width":"100%"});
	
	return select;
}